package com.heatingcharge.controller.unit;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.HeatChangeStationDTO;
import com.heatingcharge.dto.HeatSourcePlantDTO;
import com.heatingcharge.entity.unit.HeatChangeStation;
import com.heatingcharge.entity.unit.HeatSourcePlant;
import com.heatingcharge.param.HeatChangeStationParam;
import com.heatingcharge.service.unit.IHeatChangeStationService;
import com.heatingcharge.service.unit.IHeatSourcePlantService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 换热站  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-07-12
 */
@RestController
@RequestMapping("/heat-change-station")
public class HeatChangeStationController {
    @Autowired
    IHeatChangeStationService heatChangeStationService;

    @ApiOperation(value = "分页获取换热站",notes = "分页获取换热站")
    @GetMapping
    public R getHeatChangeStation(Page page, HeatChangeStationDTO heatChangeStationDTO){
        IPage<HeatChangeStation> heatChangeStationIPage = heatChangeStationService.selectHeatChangeStationPage(page,heatChangeStationDTO);
        return R.ok(heatChangeStationIPage);
    }

//    @ApiOperation(id = "获取全部换热站",notes = "获取全部换热站")
//    @GetMapping("/all")
//    public R getAllHeatSourcePlant(HeatSourcePlantDTO heatSourcePlantDTO){
//        QueryWrapper<HeatSourcePlant> queryWrapper=new QueryWrapper<>();
//        if (heatSourcePlantDTO.getCompanyId()>0){
//            queryWrapper.eq("company_id",heatSourcePlantDTO.getCompanyId());
//        }
//        List<HeatSourcePlant> heatSourcePlants = heatChangeStationService.list(queryWrapper);
//        return R.ok(heatSourcePlants);
//    }

    @ApiOperation(value = "新增换热站",notes = "新增换热站")
    @PostMapping
    public R saveChangeStation(@RequestBody HeatChangeStationParam heatChangeStationParam){
        if (heatChangeStationService.save(heatChangeStationParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "更新换热站",notes = "更新换热站")
    @PutMapping
    public R updateChangeStation(@RequestBody HeatChangeStationParam heatChangeStationParam){
        if (heatChangeStationService.update(heatChangeStationParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "删除换热站",notes = "根据主键ID删除换热站")
    @DeleteMapping("/{id}")
    public R delChangeStation(@PathVariable("id") Integer id){
        if (heatChangeStationService.removeById(id)){
            return R.ok();
        }
        return R.error();
    }
}

